package com.threads;

public class QuickSortTest {
	public static void main(String[] args) {
		int[] array = new int[]{5,9,7,6,2,0,1,8,5,3};
		QuickSort(array, 0, array.length-1);
		for(int i: array){
			System.out.println(i);
		}
	}
	
	public static void QuickSort(int[] array, int l,int r){
		if(l >= r)
			return;
		int key = array[l];
		int i = l;
		int j = r;
		while(i < j){
			while(array[j] >= key && i < j){
				j--;
			}
			if(i < j)
				array[i++] = array[j];
			while(array[i] < key && i < j){
				i++;
			}
			if(i < j)
				array[j--] = array[i];
		}
		array[i] = key;
		QuickSort(array, l, i-1);
		QuickSort(array, i+1, r);
	}
}
